﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Net.Mail;
using eschoolBO;

namespace ESCHOOL.teachers
{
    public partial class WebForm6 : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            }
        }

        protected void btnsend_Click(object sender, EventArgs e)
        {
            MailMessage MyMessage = new MailMessage();
            MailAddress SendFrom = new MailAddress("eschool123g@gmail.com");

            if (FileUpload1.HasFile)
                FileUpload1.PostedFile.SaveAs(Server.MapPath("~/admin/attachments/" + FileUpload1.FileName));

            Attachment atc = new Attachment(Server.MapPath("~/admin/attachments/" + FileUpload1.FileName));
            MyMessage.Attachments.Add(atc);


            MyMessage.To.Add(tbto.Text);
            MyMessage.From = SendFrom;
            MyMessage.Subject = tbsubject.Text;
            MyMessage.Body = tbmsg.Text;
            System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("eschool123g@gmail.com", "eschool@123");

            SmtpClient emailClient1 = new SmtpClient("smtp.gmail.com");
            emailClient1.EnableSsl = true;
            emailClient1.Port = 587;
            emailClient1.Credentials = basicAuthenticationInfo;
            emailClient1.Send(MyMessage);
            //Response.Redirect("~/teachers/TMailtoone.aspx");
            tbto.Text = ""; tbsubject.Text = ""; tbmsg.Text = ""; Label1.Visible = true;
        }
    }
}
